/* Copyright 2009 Requirements Management System 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.mags.remas.model.entity.provider;

// Generated Jan 19, 2010 2:33:54 PM by Hibernate Tools 3.2.2.GA
// powered by MAGS

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.mags.dao.provider.CacheableDataProvider;
import org.mags.remas.model.entity.EnumValue;

public class EnumValueProvider extends CacheableDataProvider<EnumValue> {
	private static final long serialVersionUID = 1L;
	private EnumNameProvider enumNameProvider;

	public EnumNameProvider getEnumNameProvider() {
		return enumNameProvider;
	}
	public void setEnumNameProvider(EnumNameProvider enumNameProvider) {
		this.enumNameProvider = enumNameProvider;
	}
	public EnumValueProvider(EnumNameProvider enumNameProvider) {
		this.enumNameProvider = enumNameProvider;
	}
	public List<EnumValue> getByEnumNameId(int enumNameId) {
		List<EnumValue> items = new ArrayList<EnumValue>();
		for(EnumValue i: this.getAll())
			if(i.getEnumName().getEnumNameId() == enumNameId)
				items.add(i);
		return items;
	}
	protected void loadProperties(EnumValue one) {
		one.setEnumName(enumNameProvider.getById(one.getEnumName().getEnumNameId()));
	}
	@Override
	public EnumValue getById(Serializable id) {
		for(EnumValue i: this.getAll())
			if(i.getEnumValueId()==((Integer)id).intValue())
				return i;
		return null;
	}
}
